package com.lg.demoleft.ui;

import android.app.Activity;
import android.content.res.XmlResourceParser;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class MainActivity extends Activity {
	private int width;
	private LinearLayout ll;
	private Animation loadAnimation;
	private TranslateAnimation cameraOutTA;
	private TextView text;
	private TranslateAnimation animation;
	private LinearLayout ll1;
	private LinearLayout ll2;
	private ImageView image;
	private TranslateAnimation animation1;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		ll1 = (LinearLayout) findViewById(R.id.top);
		ll2 = (LinearLayout) findViewById(R.id.top1);
		image = (ImageView) findViewById(R.id.menu);
		text = (TextView) findViewById(R.id.textView1);
		animation = new TranslateAnimation(Animation.ABSOLUTE, 0.0f,
				Animation.ABSOLUTE, 200f, Animation.ABSOLUTE, 0.0f,
				Animation.ABSOLUTE, 0.0f);
		animation1 = new TranslateAnimation(Animation.ABSOLUTE, 200f,
				Animation.ABSOLUTE, 0f, Animation.ABSOLUTE, 0.0f,
				Animation.ABSOLUTE, 0.0f);
		animation.setDuration(500);
		animation1.setDuration(500);
		animation.setAnimationListener(new AnimationListener() {

			@Override
			public void onAnimationStart(Animation animation) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onAnimationEnd(Animation animation) {
				ll2.clearAnimation();
				ll1.setPadding(200, 0, 0, 0);
			}
		});
		animation1.setAnimationListener(new AnimationListener() {

			@Override
			public void onAnimationStart(Animation animation) {

			}

			@Override
			public void onAnimationRepeat(Animation animation) {

			}

			@Override
			public void onAnimationEnd(Animation animation) {
				ll2.clearAnimation();
				ll1.setPadding(0, 0, 0, 0);
				image.setVisibility(View.GONE);
			}
		});
	}

	
	
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		int action = event.getAction();
		Log.i("gp", event.getX()+"");
		Log.i("gp", event.getY()+"");
		ll1.setPadding((int) event.getX(), 0, 0, 0);
		return super.onTouchEvent(event);
	}




	private boolean flag = false;

	public void clickButton(View v) {
		int id = v.getId();
		switch (id) {
		case R.id.button2:
			if (flag) {
				ll1.setPadding(0, 0, 0, 0);
				ll2.startAnimation(animation1);
			} else {
				image.setVisibility(View.VISIBLE);
				ll2.startAnimation(animation);
				
			}
			flag=!flag;
			break;
		case R.id.menu:
			text.setText("00000");
			break;
		}
	}
}